#matplotlib notebook 
#-*- coding: gbk -*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
 
#设置中文黑体
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
 
 
# 1. 准备正弦曲线数据
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
 
 
# 2. 创建画布和坐标系
fig = plt.figure(tight_layout=True)
ax = fig.add_subplot(111)
 
# 3. 绘制正弦曲线
ax.plot(x, y)
 
 
# 4. 动画设计
 
def update_points(num):
    point_ani.set_data(x[num], y[num])    # num代表当前动画第几帧
    text_pt.set_text("x=%.3f, y=%.3f"%(x[num], y[num]))
    return point_ani,text_pt,
 
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
 
plt.plot(x,y)
point_ani,= plt.plot(x[0], y[0], "ro")
text_pt = plt.text(4, 0.8, '', fontsize=16)
 
# 开始制作动画
ani = animation.FuncAnimation(fig, update_points, np.arange(0, 100), interval=100, blit=True)
 
# 5.将动画保存为gif图片（用于上传博客）
ani.save("pratice7.3.gif", writer='pillow')
 
# 6.展示图表
plt.show()